<?php
// +----------------------------------------------------------------------
// | [RhaPHP System] Copyright (c) 2017 http://www.rhaphp.com/
// +----------------------------------------------------------------------
// | [RhaPHP] 并不是自由软件,你可免费使用,未经许可不能去掉RhaPHP相关版权
// +----------------------------------------------------------------------
// | Author: Geeson <qimengkeji@vip.qq.com>
// +----------------------------------------------------------------------


namespace addons\hlapp\model;

use think\Model;

class HlappProjectEvaluate extends CommonModel
{
    // key 是 阶段标志  value 是评价数组
    public static $evaluateOption = array(
        '0'=>array("施工进度、项目劳动力安排、材料进场方面","施工质量、现场配合度方面","安全文明方面"),
        '1'=>array("项目团队认可方面","劳务队伍进场方面","合同签订情况及开工指令情况"),
        '2'=>array("项目团队认可方面","劳务队伍进场方面","合同签订情况及开工指令情况"),
        '3'=>array("施工进度及材料进场方面","施工质量方面及各工序隐蔽验收情况","现场项目部及劳务班组配合度方面","现场安全文明方面"),
        '4'=>array("施工进度及人员配备方面","现场成品保护方面","现场整改及垃圾清运方面","存不存在交楼风险"),
        '5'=>array("现场返修速度情况","现场返修质量及销项情况","维修完成后人走场清的问题"),
    );

    //状态获取器
    public function getStatusAttr($value)
    {
        $status = [0=>'不满意',1=>'满意',null=>'未评价'];
        return $status[$value];
    }
    // 项目
    public function project(){
       return $this->hasOne('HlappProject','id','projectId');
    }

    /**
     * 获取项目描述模板
     * @param $name 项目名称
     * @param $stage 项目阶段
     * @return string
     */
    public static function  getEvaluateTemplate($name,$stage){
        $template = "领导您好,我是海尔家居客服中心的客服人员,现需要对我方承接贵司的项目进行喜户回访,需占用您几分钟时间,目前 <span style='color: #5CBD1C'>".$name." </span>正处于 <span style='color: #5CBD1C'>".$stage."</span>  阶段,现针对以下几个方面,希望领导给予此项目综合评价";
        return $template;
    }

    /**
     * 评价列表
     */
    public function evaluateList($pId){
        $mode = new HlappProject();
        $sqlList = " select s.id 'sId',s.description,s.sort,e.*,p.statusId 'nowId'
                      from hl_hlapp_project_status s
                      left JOIN (select * from hl_hlapp_project_evaluate where projectId = ".$pId.") e ON s.id = e.statusId
                      left JOIN hl_hlapp_project p on p.id = e.projectId
                      order by s.sort asc";
        $list = $mode->query($sqlList);
        return $list;
    }

    //未评价的 评价
    public function noEvaluate($time=null){
        $that = $this->with('project')->where('status',null);
        if ($time){
            $that = $that->where('create_time','>',$time);
        }
        return $that->order('id','desc')->select();
    }
}